--- title: "L2-039 清点代码库" created: 2025-11-28 tags: - 算法 --- # L2-039 清点代码库 ## 题目 [L2-039 清点代码库](https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=1386335159927652362&page=1) ![[image-04fb67d9.png]] ## 思路分析 map计数 转为vector 排序 ## 代码实现 算是投机取巧 直接输出带空格的string 而不是多个int 18/25 ```cpp #include using namespace std; #define endl '\n' #define int long long using ll = long long; using ull = unsigned long long; using PII = pair; using Pll = pair; int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 }; const int inf = 0x3f3f3f3f; using PSI = pair; signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); // 若输入相同 输出相同 则重复 // 输出简化为整数 // n m int n,m; cin>>n>>m; unordered_map hx; while(n--) { string s; for(int i=0; i>tmp; s+=" "; s+=to_string(tmp); } hx[s]++; } cout< res(hx.begin(),hx.end()); sort(res.begin(),res.end(),[](const PSI& a,const PSI& b) { if (a.second != b.second) return a.second > b.second; return a.first < b.first; }); for(auto v:res) { cout< using namespace std; #define endl '\n' using ll = long long; using ull = unsigned long long; using PII = pair; using Pll = pair; int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 }; const int inf = 0x3f3f3f3f; using PIV = pair>; signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n,m;cin>>n>>m; map,int> hx; while(n--) { vector cur(m); for(int i=0; i>cur[i]; } hx[cur]++; } cout< res; for(auto v:hx){ res.push_back({v.second,v.first}); } sort(res.begin(),res.end(),[](const PIV& a,const PIV& b){ if(a.first!=b.first) return a.first>b.first; return a.second